package logic

import (
	"context"
	"fmt"
	"post/docker/mysql"
	"strings"

	"post/postrpc/internal/svc"
	"post/postrpc/postrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type RecordAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRecordAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RecordAddLogic {
	return &RecordAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *RecordAddLogic) RecordAdd(in *postrpc.RecordAddRequest) (*postrpc.RecordAddResponse, error) {
	// todo: add your logic here and delete this line

	if strings.Contains(in.Comment, "草") || strings.Contains(in.Comment, "妈") {
		return nil, fmt.Errorf("评论内容包含敏感词汇")
	}
	record := mysql.Record{

		Title:      in.Title,
		Comment:    in.Comment,
		UserId:     in.UserId,
		ActivityId: in.ActivityId,
		ClassId:    in.ClassId,
	}
	mysql.DB.Debug().Create(&record)
	return &postrpc.RecordAddResponse{
		RecordId: int64(record.ID),
	}, nil
}
